package cmd

import (
	"fmt"
	"github.com/spf13/cobra"
	"my189go/internal/session"
	"my189go/pkg/file"
)

var upCmd = &cobra.Command{
	Use:   "up",
	Short: "upload file",
	Args:  cobra.MinimumNArgs(2),
	Run: func(cmd *cobra.Command, args []string) {
		for _, v := range args {
			fmt.Println(v)
		}

		length := len(args)
		cloud := session.Join(args[length-1])
		err := file.CheckPath(cloud)
		if err != nil {
			fmt.Println(err)
			return
		}
		locals := args[:length-1]
		if err := App().Upload(cloud, locals...); err != nil {
			fmt.Println(err)
		}
	},
}
